package me.zhengjie.base;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.http.HttpStatus;

/**
 * 接口响应结果
 *
 * @author TianI
 */
@Data
@Accessors(chain = true)
public class ApiResult<T> {

    private int code;
    private String msg;
    private T data;

    /**
     * 增加，修改，删除成功响应
     */
    public final static ApiResult<?> OK = new ApiResult<>().setCode(HttpStatus.OK.value());


    /**
     * 查询成功响应
     *
     * @param data 数据
     */
    public static <T> ApiResult<T> ok(T data) {
        return new ApiResult<T>().setCode(HttpStatus.OK.value()).setData(data);
    }


    /**
     * 失败响应
     *
     * @param code 响应代码
     * @param msg 响应描述
     */
    public static <T> ApiResult<T> fail(int code, String msg) {
        return new ApiResult<T>().setCode(code).setMsg(msg);
    }


}
